'use strict';

module.exports = app => {
  const { INTEGER, DATE, STRING } = app.Sequelize;

  const ConversationInfo = app.model.define('conversation_info', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    content: STRING,
    content_type: { type: INTEGER, defaultValue: 1 }, // 1 为字符串
    created_at: { type: DATE, as: 'send_time' },
  });

  ConversationInfo.associate = function() {
    app.model.ConversationInfo.belongsTo(app.model.User, {
      as: 'send_user',
      targetKey: 'id',
      foreignKey: 'send_user_id',
    });

    app.model.ConversationInfo.belongsTo(app.model.Conversation, {
      targetKey: 'id',
      foreignKey: 'conversation_id',
    });
  };

  return ConversationInfo;
};
